package youcaihuaoa.weetop.com.ui.adapter

import android.graphics.Color
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.widget.TextView
import androidx.appcompat.widget.AppCompatEditText
import androidx.core.widget.addTextChangedListener
import com.blankj.utilcode.util.SpanUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.robot.base.model.CustomProfileItemBean
import youcaihuaoa.weetop.com.R

class TrendApplyProfileAdapter :
    BaseQuickAdapter<CustomProfileItemBean, BaseViewHolder>(R.layout.app_item_trend_apply_profile) {
    override fun convert(holder: BaseViewHolder, item: CustomProfileItemBean) {
        val tvTitle = holder.getView<TextView>(R.id.item_tv_title)
        holder.setGone(R.id.item_v_line, holder.adapterPosition == data.size - 1)
            .setText(R.id.item_edit_content, item.text)
            .setEnabled(R.id.item_edit_content, item.viewEnable ?: true)
        if (item.status == "1") {
            SpanUtils.with(tvTitle)
                .append("*")
                .setForegroundColor(Color.RED)
                .append(item.title ?: "")
                .setForegroundColor(Color.RED)
                .setForegroundColor(context.getColor(R.color.color66))
                .create()
        } else {
            tvTitle.text = item.title
            tvTitle.setTextColor(context.getColor(R.color.color66))
        }
        holder.getView<AppCompatEditText>(R.id.item_edit_content)
            .addTextChangedListener(object : TextWatcher {
                override fun beforeTextChanged(
                    s: CharSequence?,
                    start: Int,
                    count: Int,
                    after: Int
                ) {

                }

                override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
                }

                override fun afterTextChanged(s: Editable?) {
                    item.text = s.toString()
                }
            })
    }
}